<?php
session_start();
include_once "checkLogin.php";
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link href="css/menu.css" rel="stylesheet" type="text/css"/>
    <script src="js/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="js/nav.js" type="text/javascript"></script>
    <link rel="stylesheet" href="layui/css/layui.css">
    <script src="js/TweenMax.min.js"></script>
    <link href="css/word.css" rel="stylesheet" type="text/css"/>
    <title>修改图书信息</title>
    <style>
        .layui-form {
            width: 50%;
            margin: 1% auto;
        }

        #now {
            margin-left: 5%;
            margin-top: 1%;
        }
    </style>
</head>
<body>
<canvas id="Mycanvas" style="position: absolute;left: 0%;width: 100%;height: 99%"></canvas>
<div id="main">
    <header>
        <div id="header1">
            <div id="a"></div>
            <img src="img/logo1.png">
            <h2 class="letter-wrap"  data-stagger="-0.015">清华大学图书馆管理系统</h2>
            <?php
            include_once "conn.php";
            $main = new main();
            $id = $_GET['id'];
            $info = $main->bookinfo($id);
            ?>
            <span>当前登录用户：<?php echo $_SESSION['admin']?></span>
        </div>
    </header>
    <div class="navmain">
        <div id="time"><span></span></div>
        <ul id="nav_all">
            <li><a href="index.php">首页</a></li>
            <?php
            include_once "conn.php";
            $main = new main();
            $info1 = $main->checkAdmin($_SESSION['admin']);
            if ($info1['system']){
                ?>
                <li><a href="#">系统设置</a>
                    <ul style="display: none;">
                        <li><a href="library.php">图书馆信息</a></li>
                        <li><a href="admin.php">管理员设置</a></li>
                        <li><a href="#">参数设置</a></li>
                        <li><a href="shujia.php">书架设置</a></li>
                    </ul>
                </li>
                <?php
            }
            if ($info1['readerset']){
                ?>
                <li><a href="#">读者管理</a>
                    <ul style="display: none;">
                        <li><a href="readertype.php">读者类型管理</a></li>
                        <li><a href="user.php">读者档案管理</a></li>
                    </ul>
                </li>
                <?php
            }
            if ($info1['bookset']){
                ?>
                <li><a href="tushudangan.php">图书档案管理</a></li>
                <?php
            }
            if ($info1['book']){
                ?>
                <li><a>图书借还</a>
                    <ul style="display: none;">
                        <li><a href="bookjieyue.php">图书借阅</a></li>
                        <li><a href="bookxujie.php">图书续借</a></li>
                        <li><a href="bookback.php">图书归还</a></li>
                    </ul>
                </li>
                <?php
            }
            if ($info1['syschaxun']){
                ?>
                <li> <a>系统查询</a>
                    <ul style="display: none;">
                        <li><a href="tushudanganchaxun.php">图书档案查询</a></li>
                        <li><a href="jieyuechaxun.php">图书借阅查询</a></li>
                        <li><a href="jieyue.php">借阅到期提醒</a></li>
                    </ul>
                </li>
                <?php
            }
            ?>
            <li>
                <a href="pw.php">更改口令</a>
            </li>
            <li><a href="zhuxiao.php">注销</a> </li>
        </ul>
    </div>
    <div id="b"></div>
    <div id="c">
        <div id="now">当前位置：图书档案管理 > 修改图书信息 >>></div>
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">条形码</label>
                <div class="layui-input-block">
                    <input type="number" name="code" required lay-verify="required" value="<?php echo $info['barcode'] ?>"
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">图书名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="bookname" required lay-verify="required" value="<?php echo $info['bookname'] ?>"
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">图书类型</label>
                <div class="layui-input-inline">
                    <select name="booktype" lay-verify="required">
                        <?php
                        include_once "conn.php";
                        $main = new main();
                        $result = $main->booktype();
                        print_r($result);
                        for ($i = 0; $i < count($result); $i++) {
                            ?>
                            <option value="<?php echo $result[$i]['id'] ?>" <?php echo $result[$i]['type']== $info['type']?'selected':'' ?>><?php echo $result[$i]['type']?></option>
                            <?php
                        }
                        ?>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">作者</label>
                <div class="layui-input-inline">
                    <input type="text" name="author" required lay-verify="required" value="<?php echo $info['author']?>"
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">译者</label>
                <div class="layui-input-inline">
                    <input type="text" name="fanyi" required lay-verify="required" value="<?php echo $info['fanyi']?>"
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">出版社</label>
                <div class="layui-input-inline">
                    <select name="chuban" lay-verify="required">
                        <?php
                        include_once "conn.php";
                        $main = new main();
                        $result = $main->chubanshe();
                        print_r($result);
                        for ($i = 0; $i < count($result); $i++) {
                            ?>
                            <option value="<?php echo $result[$i]['ISBN'] ?>" <?php echo $result[$i]['chuban']==$info['chuban']?'selected':''?>><?php echo $result[$i]['chuban'] ?></option>
                            <?php
                        }
                        ?>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">价格</label>
                <div class="layui-input-block">
                    <input type="number" name="price" required lay-verify="required" value="<?php echo $info['price']?>"
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">库存</label>
                <div class="layui-input-inline">
                    <input type="number" name="kucun" required lay-verify="required"  value="<?php echo $info['storage'] ?>"
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">页码</label>
                <div class="layui-input-inline">
                    <input type="number" name="page" required lay-verify="required" value="<?php echo $info['page']?>"
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">书架</label>
                <div class="layui-input-inline">
                    <select  name="shujia" lay-verify="required">
                        <?php
                        include_once "conn.php";
                        $main = new main();
                        $result = $main->shujia();
                        for ($i = 0; $i < count($result); $i++) {
                            ?>
                            <option value="<?php echo $result[$i]['id'] ?>" <?php echo $result[$i]['name']==$info['name']?'selected':'' ?>> <?php echo $result[$i]['name'] ?></option>
                            <?php
                        }
                        ?>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button id="btn" class="layui-btn" lay-submit lay-filter="formDemo">修改</button>
                    <button type="button" class="layui-btn layui-btn-primary" onclick="history.back();">返回</button>
                </div>
            </div>
        </form>
    </div>
    <footer>
        <hr id="one">
        <hr id="two">
        CopyRight © 2019 www.cdp.cn.com 清华大学图书馆
    </footer>
</div>
</body>
<script src="layui/layui.js"></script>
<script src="js/logo.js"></script>
<script src="js/bg.js"></script>
<script>
    //Demo
    layui.use('form', function () {
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function (data) {
            console.log(data.field);//当前容器的全部表单字段，名值对形式：{name: value}
            $(function () {
                $.ajax({
                    type: "POST",
                    url: "xiugai1book.php",
                    data: {
                        id:<?php echo $_GET['id']?>,
                        author: data.field.author,
                        bookname: data.field.bookname,
                        code: data.field.code,
                        fanyi: data.field.fanyi,
                        page: data.field.page,
                        price: data.field.price,
                        booktype: data.field.booktype,
                        chuban: data.field.chuban,
                        shujia: data.field.shujia,
                        kucun : data.field.kucun
                    },
                    dataType: 'JSON',
                    cache: false, //不缓存此页面
                    success: function (data) {
                        console.log(data);
                        if (data.error === 1) {
                            layer.msg('修改成功!');
                            setTimeout(function () {
                                window.location.href=document.referrer;
                            },500)
                        } else {
                            layer.msg('修改失败!请重试!');
                        }
                    }
                })
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
</script>
</html>